package com.viphuli.http.handler;

import java.util.List;

import com.viphuli.app.R;
import com.viphuli.common.Constants;
import com.viphuli.fragment.PurchaseOrderPayFragment;
import com.viphuli.http.bean.page.PurchasePayPage;
import com.viphuli.http.bean.part.PurchaseOrder;
import com.viphuli.http.bean.part.PurchasePayTicket;

public class PurchaseOrderPayInfoResponseHandler extends MyBaseHttpResponseHandler<PurchaseOrderPayFragment, PurchasePayPage> {

	@Override
	public void deal() {
		PurchaseOrder order = page.getOrder();

		//填充数据
		caller.getNameText().setText(order.getName());
		caller.getPriceText().setText(order.price());
		caller.getUserNameText().setText(order.getPersonContact());
		caller.getUserPhoneText().setText(order.getTel());
		caller.getSiteText().setText(order.address());
		caller.getTimeText().setText(order.createTimeMinute());

		//代金劵信息
		PurchasePayTicket curTicket = null;
		List<PurchasePayTicket> tickets = page.getTicketList();
		
		caller.setTickets(tickets);//当前订单的可用代金劵
		
		for (PurchasePayTicket ticket : tickets) {

			/**
			 * 条件1：状态有效
			 * 条件2：第一个可用金额（可用金额的顺序由服务端决定）
			 */
			if (Constants.TICKET_IS_VALID == ticket.getIsValid()) {

				curTicket = ticket;
				break;
			}

		}

		if (curTicket == null) {

			caller.getTicketText().setText(caller.getString(R.string.str_ticket_empty));

		} else {

			caller.getTicketText().setText(curTicket.getName());
			caller.setTicket(curTicket);

		}

		//获得支付金额
		caller.initPayPrice();

		//隐藏加载对话框
		caller.notEmpty();
	}

}
